#include "random_in.h"

#define MAX_READ_ENTROPY_COUNTER 10
static int READ_ENTROPY_COUNTER = 0;

int sys_entropy_counter_add()
{
    return ++READ_ENTROPY_COUNTER;
}

int sys_entropy_counter_reset()
{
    READ_ENTROPY_COUNTER = 0;
    return READ_ENTROPY_COUNTER;
}

int sys_entropy_counter_get()
{
    return READ_ENTROPY_COUNTER;
}

int sys_entropy_counter_arrived()
{
    return (READ_ENTROPY_COUNTER >= MAX_READ_ENTROPY_COUNTER);
}

static int random_state_ = RANDOM_STATE_INIT;

static inline int is_invalid_state(int state)
{
    if( state != RANDOM_STATE_INIT &&
        state != RANDOM_STATE_WORK &&
        state != RANDOM_STATE_ERROR)
        return 1;
    return 0;
}

int random_state_get()
{
    return random_state_;
}

int random_state_set(int state)
{
    if(is_invalid_state(state))
        return -EINVAL;
    random_state_ = state;
    return 0;
}

int random_state_is(int state)
{
    if(is_invalid_state(state))
        return 0;

    return (state == random_state_);
}